package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.Comment;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import com.zrwl.poscloud.xo.mapper.CommentMapper;
import com.zrwl.poscloud.xo.service.CommentService;
import com.zrwl.poscloud.xo.vo.CommentVO;

import javax.annotation.Resource;

/**
 * 事件评论 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@Service
public class CommentServiceImpl extends SuperServiceImpl<CommentMapper,Comment> implements CommentService {

    @Autowired
    private CommentService commentService;
    @Resource
    private CommentMapper commentMapper;
    @Override
    public IPage<CommentVO> getPageList(CommentVO commentVO){
       Page<Comment> page = new Page<>();
       page.setCurrent(commentVO.getCurrentPage());
       page.setSize(commentVO.getPageSize());
       IPage<CommentVO> pageList = commentMapper.getPageList(page, commentVO);
       List<CommentVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<Comment> getAllList(CommentVO commentVO){
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<Comment> list = commentService.list(queryWrapper);
        return list;
}
    @Override
    public String add(CommentVO commentVO){
        Comment entity = new Comment();
        BeanUtils.copyProperties(commentVO, entity, SysConf.STATUS);
        entity.insert();
        commentVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(CommentVO commentVO){
        Comment entity = commentService.getById(commentVO.getUid());
        BeanUtils.copyProperties(commentVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(CommentVO commentVO){
        Comment entity = commentService.getById(commentVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}

    @Override
    public int getNum(CommentVO commentVO) {
        int cnum=commentMapper.getNum(commentVO);
        return cnum;
    }

    public int getNums(CommentVO commentVO) {
        int cnum=commentMapper.getNums(commentVO);
        return cnum;
    }

    @Override
    public List<CommentVO> getRoot(CommentVO commentVO) {

        List<CommentVO> list = commentMapper.getRoot(commentVO);

        return list;
    }

    public List<CommentVO> getNext(CommentVO commentVO){
        List<CommentVO> list = commentMapper.getNext(commentVO);
        return list;
    }
}
